<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>留言详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container">
        <a class="navbar-brand" href="#">留言板系统</a>
        <div class="navbar-collapse">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" href="/messages">留言列表</a>
                </li>
            </ul>
            <span class="navbar-text me-3" th:text="'欢迎，' + ${session.currentUser.studentName}"></span>
            <a href="/logout" class="btn btn-outline-light">退出</a>
        </div>
    </div>
</nav>

<div class="container mt-4">
    <div class="card mb-4">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4 th:text="${message.title}"></h4>
            <form th:if="${session.currentUser.studentName == message.writer}" th:action="@{/messages/{id}/delete(id=${message.messageID})}" method="post" class="d-inline">
                <button type="submit" class="btn btn-sm btn-outline-danger">删除留言</button>
            </form>
        </div>
        <div class="card-body">
            <p class="card-text" th:text="${message.content}"></p>
            <div class="d-flex justify-content-between align-items-center">
                <small class="text-muted" th:text="'发布者：' + ${message.writer}"></small>
                <small class="text-muted" th:text="${#dates.format(message.writeDate, 'yyyy-MM-dd HH:mm')}"></small>
            </div>
        </div>
    </div>

    <h5 class="mb-3">回复</h5>

    <!-- 回复列表 -->
    <div class="list-group mb-4">
        <div th:each="revert : ${reverts}" class="list-group-item">
            <div class="d-flex w-100 justify-content-between">
                <p class="mb-1" th:text="${revert.content}"></p>
                <small th:text="${#dates.format(revert.writeDate, 'yyyy-MM-dd HH:mm')}"></small>
            </div>
            <small th:text="'回复者：' + ${revert.writer}"></small>
            <form th:if="${session.currentUser.studentName == revert.writer}" th:action="@{/reverts/{id}/delete(id=${revert.revertID})}" method="post" class="mt-2">
                <button type="submit" class="btn btn-sm btn-outline-danger">删除回复</button>
            </form>
        </div>
    </div>

    <!-- 添加回复表单 -->
    <div class="card">
        <div class="card-header">
            <h5>添加回复</h5>
        </div>
        <div class="card-body">
            <form th:action="@{/reverts}" th:object="${newRevert}" method="post">
                <input type="hidden" th:field="*{messageID}">
                <div class="mb-3">
                    <label for="content" class="form-label">回复内容</label>
                    <textarea class="form-control" id="content" th:field="*{content}" rows="3" required></textarea>
                </div>
                <button type="submit" class="btn btn-primary">提交回复</button>
            </form>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>